package com.soonzlab.englishlearning.client;

//import com.soonzlab.englishstudy.shared.FieldVerifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.types.ImageStyle;
import com.smartgwt.client.types.Positioning;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.types.Visibility;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.HTMLFlow;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangeHandler;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;

import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.soonzlab.englishlearning.client.obj.ArticleObj;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class EnglishLearning extends HLayout implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	/**
	 * Create a remote service proxy to talk to the server-side Greeting
	 * service.
	 */
	private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

	ArrayList<ArticleObj> aricleArray = null;
	String resultStr = "";
	Img loadingImgLarge = new Img ("/images/ajax-loader-large.gif");
	Img loadingImgSmall = new Img ("/images/ajax-loader-small.gif",16,16);
	Img loadingTransSmall = new Img ("/images/ajax-loader-small.gif",16,16);
	HTMLPane htmlPaneTranslate = null;
	HTMLPane htmlPaneOriginal = null;
	HTMLPane articlePic = null;
	HTMLPane articleDesc = null;
	String voaIcon = "/images/VOARSSIcon.gif";
	String articleDescTemplate = "";
	String articleDescContent = 
    	"<span style='font-size:13pt'><b>TITLE</b></span><BR>" +
    	"<span style='font-size:11pt'>DESCRIPTION</span><BR>" +
    	"Original Article:&nbsp;<a href='URL' target='_blank'>Visit Orinal Site</a><BR><BR>" +
    	"<object id=\"single1\" width=\"300\" height=\"24\" data=\"http://www.voanews.com/MediaAssets2/player/jw/player.swf\" type=\"application/x-shockwave-flash\">" +
    	"<param name=\"data\" value=\"http://www.voanews.com/MediaAssets2/player/jw/player.swf\">" +
		"<param name=\"name\" value=\"single1\">" +
		"<param name=\"allowfullscreen\" value=\"true\">" +
		"<param name=\"allowsc-riptaccess\" value=\"always\">" +
		"<param name=\"wmode\" value=\"transparent\">" +
		"<param name=\"flashvars\" value=\"file=AUDIO&amp;backcolor=7FA3BD&amp;frontcolor=FFFFFF\">" +
		"<param name=\"src\" value=\"http://www.voanews.com/MediaAssets2/player/jw/player.swf\">" +
		"<param name=\"bgcolor\" value=\"#ffffff\">" +
		"</object>";
	String noContent = 
    	"Title:<BR>" +
    	"Description:<BR>" +
    	"Original Article:<BR>" ;
	VLayout vlayout = null;
	Portlet portletOriginal = null;
	Portlet portletTranslate = null;
	PortalLayout portalLayout = new PortalLayout(2); 
	String currentFontSizeStyle = "15";
	String currentLanguage = "CHINESE_TRADITIONAL";
	//String ditionaryScript = "<script src='ldwclick_ec.js' type='text/javascript'></script>";
	String ditionarySectionStart = "<div id=\"wordclickDiv\" class=\"wordclick\" onmousemove=\"this.style.cursor = typeof(mw) != 'undefined' &amp;&amp; typeof(mw.wordclick) != 'undefined' &amp;&amp; mw.wordclick.isEnabled() ? 'url(http://www.merriam-webster.com/wordclick.cur), help' : 'default';\">";
	String ditionarySectionEnd = "</div>";
	String currentOriginalContent = "";
	
	IButton signInButton = new IButton("Login with Google");  
	Label signInLabel = new Label("New feature! Login to Google will automatically publish the word that you search to your Google Calendar.");

	public void onModuleLoad() {

		setTrigger(this);
		
		// Define Tree Container
		final VLayout treeVLayout = new VLayout();
		treeVLayout.setWidth(350);
		treeVLayout.setHeight(610);
		
		final TreeGrid treeGrid = new TreeGrid();
		treeGrid.setWidth100();
		//treeGrid.setHeight(755);
		treeGrid.setBackgroundColor("#FEFF91");
		TreeGridField field = new TreeGridField("Name",	"VOA English Report List");
		field.setCanSort(false);
		treeGrid.setFields(field);

		treeVLayout.setParentElement(this);  
		treeVLayout.setShowEdges(true); 
		treeVLayout.setBackgroundColor("#FEFF91");
		treeVLayout.setTop(157);  
		treeVLayout.setLeft(0);   
		treeVLayout.setVisibility(Visibility.HIDDEN);
		
        //label.setValign(VerticalAlignment.CENTER);  
        //label.setAlign(Alignment.CENTER);  
		treeVLayout.setAnimateTime(800); // milliseconds 
		
		//Define Tree
		final Tree tree = new Tree();
		tree.setModelType(TreeModelType.PARENT);
		tree.setNameProperty("Name");
		tree.setIdField("EmployeeId");
		tree.setParentIdField("ReportsTo");
		tree.setShowRoot(true);

		//close Button
		
		final IButton switchButtonClose = new IButton("Close");  
		switchButtonClose.setWidth100();  
		switchButtonClose.setShowRollOver(true);  
		switchButtonClose.setShowDisabled(true);  
		switchButtonClose.setShowDown(true);  
		switchButtonClose.setTitleStyle("stretchTitle");
		switchButtonClose.setBackgroundColor("#cccccc");
		//switchButton.setIcon("silk/printer.png");  
        
		switchButtonClose.addClickHandler(
			new ClickHandler(){
				@Override
				public void onClick(ClickEvent event) {
					treeVLayout.animateHide(AnimationEffect.WIPE);   
				}
		});
		
		
		treeVLayout.addMember(treeGrid);
		treeVLayout.addMember(switchButtonClose);
		
		//Define Article Info Verticle Layout
		vlayout = new VLayout();
		vlayout.setWidth(1012);
		vlayout.setHeight(600);

		//Define Article Content Control Bar
		final HLayout canvas = new HLayout();  
		canvas.setHeight(160); 
		canvas.setWidth("100%");  
		canvas.setPadding(2);  
		canvas.setCanDragResize(true);  
		canvas.setShowEdges(true);  

		
		final VLayout pictureVLayout = new VLayout();
		pictureVLayout.setWidth(150);
		//pictureVLayout.setHeight(600);
		
		//tree Switch button
		final IButton switchButton = new IButton("Menu");  
		switchButton.setWidth(100);  
		switchButton.setShowRollOver(true);  
		switchButton.setShowDisabled(true);  
		switchButton.setShowDown(true);  
		switchButton.setTitleStyle("stretchTitle");  
		//switchButton.setIcon("silk/printer.png");  
        
		switchButton.addClickHandler(
			new ClickHandler(){
				@Override
				public void onClick(ClickEvent event) {
					if(treeVLayout.getVisibility().equals(Visibility.HIDDEN)){
						treeVLayout.animateShow(AnimationEffect.WIPE);
						switchButton.setTitle("Close");
					}else{
						treeVLayout.animateHide(AnimationEffect.WIPE);
						switchButton.setTitle("Menu");
					}
				}
		});
		
		//Picture
		articlePic = new HTMLPane();  
		articlePic.setWidth100();
		//articlePic.setPadding(15);
        String contents = "<img style='width:100px' src='"+voaIcon+"' />";  
        articlePic.setContents(contents);  

        //Content
        articleDesc = new HTMLPane();  
        articleDesc.setWidth(570);
        articleDesc.setMargin(5);
        articleDesc.setStyleName("ArticleContent");
        articleDesc.setContents(noContent);  
		
        
        //Style & Language Setting
        //final VLayout contentControlerVLayout = new VLayout();
        final DynamicForm controlForm = new DynamicForm();
        
        //language
        final SelectItem languageSelect = new SelectItem();  
        languageSelect.setTitle("Language");  
        languageSelect.setValueMap("CHINESE_TRADITIONAL","CHINESE_SIMPLIFIED","GERMAN","FRENCH","JAPANESE","KOREAN","SPANISH","THAI","VIETNAMESE");
        languageSelect.setDefaultValues("CHINESE_TRADITIONAL");
        languageSelect.addChangedHandler(
	    		new ChangedHandler(){
					@Override
					public void onChanged(ChangedEvent event) {
						currentLanguage = (String)languageSelect.getValue();
					}
	    	
	        });
        
        //style
        final SelectItem styleSelect = new SelectItem();  
        styleSelect.setTitle("Style");  
               
        LinkedHashMap<String, String> styleMap = new LinkedHashMap<String, String>();
		styleMap.put("Classical", "Classical");
		styleMap.put("Magazine", "Magazine");
		styleMap.put("Warm", "Warm");
		styleMap.put("Contrast", "Contrast");
		styleSelect.setValueMap(styleMap);
		styleSelect.setDefaultValues("Classical");
		
		//font size
		final SelectItem fontSizeSelect = new SelectItem();  
		fontSizeSelect.setTitle("Font Size");  
		fontSizeSelect.setValueMap("12","15","20");
		fontSizeSelect.setDefaultValues("15");
		fontSizeSelect.addChangedHandler(
	    		new ChangedHandler(){
					@Override
					public void onChanged(ChangedEvent event) {
						if("12".equals(fontSizeSelect.getValue())){
							String style = styleSelect.getValue() + "12";
							htmlPaneOriginal.setStyleName(style);
							htmlPaneTranslate.setStyleName(style);
						}else if("15".equals(fontSizeSelect.getValue())){
							String style = styleSelect.getValue() + "15";
							htmlPaneOriginal.setStyleName(style);
							htmlPaneTranslate.setStyleName(style);
						}else if("20".equals(fontSizeSelect.getValue())){
							String style = styleSelect.getValue() + "20";
							htmlPaneOriginal.setStyleName(style);
							htmlPaneTranslate.setStyleName(style);
						}
					}
	    	
	        });
		
		styleSelect.addChangedHandler(new ChangedHandler() {
			public void onChanged(ChangedEvent event) {
				if("12".equals(fontSizeSelect.getValue())){
					String style = styleSelect.getValue() + "12";
					htmlPaneOriginal.setStyleName(style);
					htmlPaneTranslate.setStyleName(style);
				}else if("15".equals(fontSizeSelect.getValue())){
					String style = styleSelect.getValue() + "15";
					htmlPaneOriginal.setStyleName(style);
					htmlPaneTranslate.setStyleName(style);
				}else if("20".equals(fontSizeSelect.getValue())){
					String style = styleSelect.getValue() + "20";
					htmlPaneOriginal.setStyleName(style);
					htmlPaneTranslate.setStyleName(style);
				}
			}
		});
		
		final SelectItem dictionarySelect = new SelectItem();  
		dictionarySelect.setTitle("Dictionary");  
		LinkedHashMap<String, String> dictionaryValueMap = new LinkedHashMap<String, String>();
		dictionaryValueMap.put("dreye", "譯點通(Chinese)");
		dictionaryValueMap.put("Learner", "Learner's Dictionary");
		dictionarySelect.setValueMap(dictionaryValueMap);
		dictionarySelect.setDefaultValues("dreye");
		
		dictionarySelect.addChangedHandler(
	    		new ChangedHandler(){
					@Override
					public void onChanged(ChangedEvent event) {
						if("dreye".equals(dictionarySelect.getValue())){
							String article = 
							ditionarySectionStart
							+ currentOriginalContent
							+ ditionarySectionEnd;
							htmlPaneOriginal.setContents(article);
							changeDitcionary("ec");
						}else{
							String article = 
							ditionarySectionStart
							+ currentOriginalContent
							+ ditionarySectionEnd;
							htmlPaneOriginal.setContents(article);
							changeDitcionary("ee");
						}
					}
	    	
	        });
		
		//view mode
		final RadioGroupItem viewModeRadio = new RadioGroupItem();  
        
		LinkedHashMap<String, String> viewModeValuMap = new LinkedHashMap<String, String>();
		viewModeValuMap.put("Refer", "Refer");
		viewModeValuMap.put("English", "English");
		
        viewModeRadio.setVertical(false);  
        viewModeRadio.setValueMap(viewModeValuMap);  
        viewModeRadio.setRedrawOnChange(true);
        viewModeRadio.setTitle("View Mode");
        viewModeRadio.setDefaultValue("Refer");
        
        viewModeRadio.addChangedHandler(
    		new ChangedHandler(){
				@Override
				public void onChanged(ChangedEvent event) {
					if("Refer".equals(viewModeRadio.getValue())){
						vlayout.removeMember(portalLayout);
						portalLayout = new PortalLayout(2);
				        portalLayout.setWidth100();  
				        portalLayout.setHeight(600);
				        portalLayout.addPortlet(portletOriginal);
				        portalLayout.addPortlet(portletTranslate);
				        vlayout.addMember(portalLayout);
					}else{
						vlayout.removeMember(portalLayout);
						portalLayout = new PortalLayout(1);
				        portalLayout.setWidth100();  
				        portalLayout.setHeight(600);
				        portalLayout.addPortlet(portletOriginal);
				        vlayout.addMember(portalLayout);
					}
				}
    	
        });
        
        
        //viewModeRadio.setDefaultValues("Pair");
  /*
		
		SelectItem viewModeRadio = new SelectItem();  
		fontSizeSelect.setTitle("Font Size");  
		fontSizeSelect.setValueMap("11","12","13","14","15","16","17","18","19","20");
		
		RadioGroupItem viewModeRadioGroup = new RadioGroupItem();
		viewModeRadioGroup.setDefaultValue("Classical");
		viewModeRadioGroup.setTitle("Style");
		viewModeRadioGroup.setShowTitle(true);
		viewModeRadioGroup.setValueMap(styleMap);
	*/	
		
		controlForm.setFields(languageSelect,styleSelect,fontSizeSelect,dictionarySelect,viewModeRadio);
		controlForm.setWidth(250);
		controlForm.setPadding(5);

		//contentControlerVLayout.addChild(controlForm);
		//contentControlerVLayout.setHeight100();

		pictureVLayout.addMember(articlePic);
		pictureVLayout.addMember(switchButton);
		
		//canvas.addMember(switchButton);
		canvas.addMember(pictureVLayout);
		canvas.addMember(articleDesc);
		canvas.addMember(controlForm);
		
		//
		HLayout functionBar = new HLayout();
		functionBar.setWidth100();
		// Google Sign Button
		
		signInButton.setWidth(150);
		signInButton.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				if(signInButton.getTitle().equals("Logout")){
					greetingService.logout(
							new AsyncCallback<Void>(){

								@Override
								public void onFailure(Throwable caught) {

								}

								@Override
								public void onSuccess(Void result) {
									signInButton.setTitle("Login with Google");
								}
						
					});
				}else{
					Window.open("/googledataauthservlet", "LoginwithGoogle", "");
				}
			}
		});
		
		signInLabel.setWidth(860);
	
		functionBar.addMember(signInLabel);
		functionBar.addMember(signInButton);
		
		//portal
		portalLayout = new PortalLayout(2);  
        portalLayout.setWidth100();  
        portalLayout.setHeight(600);  
		
        //original context portlet
        portletOriginal = new Portlet(); 
        portletOriginal.setTitle("Original Article");
        portletOriginal.setHeight(600);
        
        htmlPaneOriginal = new HTMLPane();
        htmlPaneOriginal.setWidth100();
        htmlPaneOriginal.setHeight(600);
        htmlPaneOriginal.setShowEdges(false);
        htmlPaneOriginal.setStyleName("Classical15");
       // htmlPaneOriginal.addStyleName("FontSize14");
		String contentsOriginal = "Original Article";
		htmlPaneOriginal.setContents(contentsOriginal);
   
        portletOriginal.addChild(htmlPaneOriginal);
        
        //translate portlet
        portletTranslate = new Portlet();  
        portletTranslate.setTitle("Translated");
        portletTranslate.setHeight(600);
        
        htmlPaneTranslate = new HTMLPane();
        htmlPaneTranslate.setWidth100();
        htmlPaneTranslate.setHeight(600);
        htmlPaneTranslate.setShowEdges(false);
        htmlPaneTranslate.setStyleName("Classical15");
        //htmlPaneTranslate.addStyleName("FontSize14");
		String contentsTranslate = "Translated";
		htmlPaneTranslate.setContents(contentsTranslate);
        
		portletTranslate.addChild(htmlPaneTranslate);
		portletTranslate.addChild(loadingTransSmall);
		
		loadingTransSmall.setPosition(Positioning.RELATIVE);
		loadingTransSmall.setLeft(180);
		loadingTransSmall.setTop(35);
		loadingTransSmall.setVisible(false);
        portalLayout.addPortlet(portletOriginal); 
        portalLayout.addPortlet(portletTranslate); 
		
        vlayout.addMember(canvas);
        vlayout.addMember(functionBar);
        vlayout.addMember(portalLayout);
        
        //addMember(treeGrid);
		addMember(vlayout);
		
		RootPanel.get("nameFieldContainer").add(this);

		//this.addChild(loadingImgSmall);
		
		//loadingImgSmall.setPosition(Positioning.RELATIVE);
		//loadingImgSmall.setLeft(55);
		//loadingImgSmall.setTop(187);
		redraw();
        
		
        
        treeGrid.addRecordClickHandler(new RecordClickHandler() {
			public void onRecordClick(RecordClickEvent event) {
				String articlId = event.getRecord().getAttributeAsString("EmployeeId");
				// htmlPane

				try{
					Integer.valueOf(articlId);
					for (ArticleObj articleObj : aricleArray) {
						if (articleObj.getGuid().equals(articlId)) {
							currentOriginalContent = articleObj.getContent();
							if(articleObj.getPicUrl().length() == 0){
								articlePic.setContents("<img style='width:100px' src='"+voaIcon+"' />");
							}else{
								articlePic.setContents("<img style='width:150px' src='"+articleObj.getPicUrl()+"' />");
							}

							String article = 
							ditionarySectionStart
							+ currentOriginalContent
							+ ditionarySectionEnd;
							htmlPaneOriginal.setContents(article);
							
							setTranslate(articleObj.getContent());
							//articleDesc
							String temp = new String(articleDescContent); 
							
							temp = temp.replaceAll("TITLE", articleObj.getTitle());
							temp = temp.replaceAll("DESCRIPTION", articleObj.getDescription());
							temp = temp.replaceAll("URL", articleObj.getOriginUrl());
							temp = temp.replaceAll("AUDIO", articleObj.getAudioUrl());

							articleDesc.setContents(temp);
		
						}
					}
				}catch(Exception e){

				}
				
			}
		});
		
        treeGrid.addDrawHandler(new DrawHandler() {
			public void onDraw(DrawEvent event) {
				tree.openAll();

			}
		});

		greetingService.getNewArticle(new AsyncCallback<ArrayList<ArticleObj>>() {
			public void onFailure(Throwable caught) {
				Window.alert(caught.getLocalizedMessage());
			}

			@Override
			public void onSuccess(ArrayList<ArticleObj> result) {
				aricleArray = result;
				//Window.alert(result.size()+"");
				setDataToTree(tree, aricleArray);
				treeGrid.setData(tree);
				loadingImgSmall.setVisible(false);
				treeGrid.redraw();
				tree.openAll();
				treeVLayout.animateShow(AnimationEffect.WIPE);
				switchButton.setTitle("Close");
			}
		});

		greetingService.getLoginUser(new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				Window.alert(caught.getMessage());			
			}

			@Override
			public void onSuccess(String result) {
				if(result != null && result.length() != 0){
					signInLabel.setContents(result);
					signInButton.setTitle("Logout");
				}
			}
			
		});
	}

	public void setTranslate(String content) {
		htmlPaneTranslate.setContents("");
		loadingTransSmall.setVisible(true);
		greetingService.getTranslate(content, this.currentLanguage, new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				resultStr = "";
				Window.alert("fiald" + resultStr);
				loadingTransSmall.setVisible(false);
			}

			@Override
			public void onSuccess(String result) {
				resultStr = result;
				if(resultStr != null && resultStr.length() != 0){
					htmlPaneTranslate.setContents(resultStr);
				}else{
					htmlPaneTranslate.setContents("Translate fail, please choose article again.");
				}
				loadingTransSmall.setVisible(false);
			}
			
		});

	}
	
	public void setDataToTree(Tree tree, ArrayList<ArticleObj> dataArray) {
		
		Map map = new HashMap();
		
		for (int i = 0; i < dataArray.size(); i++) {
			ArticleObj articleObj = dataArray.get(i);
			map.put(articleObj.getCategory(), articleObj.getCategory());
		}
		Set keySet = map.keySet();
		Iterator it = keySet.iterator();
		TreeNode[] treeNodes = new TreeNode[dataArray.size() + map.size()];
		
		for(int i=0; it.hasNext(); i++){
			String categoryName = (String)map.get((String)it.next());
			treeNodes[i]=new EmployeeTreeNode(categoryName,"0", categoryName);
		}
		
		for (int i = map.size(); i < dataArray.size()+map.size(); i++) {
			ArticleObj articleObj = dataArray.get(i-map.size());

			EmployeeTreeNode e = new EmployeeTreeNode(articleObj.getGuid(),articleObj.getCategory(), articleObj.getTitle());

			treeNodes[i] = e;
		}
		tree.setData(treeNodes);
	}

	public static class EmployeeTreeNode extends TreeNode {

		public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
			setEmployeeId(employeeId);
			setReportsTo(reportsTo);
			setName(name);
		}

		public void setEmployeeId(String value) {
			setAttribute("EmployeeId", value);
		}

		public void setReportsTo(String value) {
			setAttribute("ReportsTo", value);
		}

		public void setName(String name) {
			setAttribute("Name", name);
		}
	}
	
	public void setFontSize(String fontSizeStyle){
		htmlPaneOriginal.removeStyleName(currentFontSizeStyle);
		htmlPaneTranslate.removeStyleName(currentFontSizeStyle);
		currentFontSizeStyle = fontSizeStyle;
		htmlPaneOriginal.addStyleName(currentFontSizeStyle);
		htmlPaneTranslate.addStyleName("currentFontSizeStyle");
	}
	
	public native void changeDitcionary(String dictionary) /*-{
	
	
	//$wnd.alert(""+$wnd.dictionary_url);
	if (dictionary == "ee") {
		$wnd.dictionary_url = $wnd.dictionary_ee;
	}else{
		$wnd.dictionary_url = $wnd.dictionary_ec;
	}
}-*/;
	
	public void saveToGoogleDoc(String word, String vocabulary) {

		greetingService.saveToCalendar(word, vocabulary, new AsyncCallback<String>(){

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("fiald:" + caught.getMessage());
				signInLabel.setContents(caught.getMessage());
			}

			@Override
			public void onSuccess(String result) {
				if(result != null && result.length() != 0){
					signInLabel.setContents(result);
				}
			}
			
		});
		//Window.alert("selected word = " + word);

	}
	
	public native void setTrigger(EnglishLearning x)/*-{

	$wnd.saveToGWTServer = function (word, vocabulary) {
	x.@com.soonzlab.englishlearning.client.EnglishLearning::saveToGoogleDoc(Ljava/lang/String;Ljava/lang/String;)(word, vocabulary);

	};

	}-*/;
	

}
